export const modifyMap = (viewer) => {
  // 获取地球影像图层
  const baseLayer = viewer.imageryLayers.get(0);
  // 设置2个变量，用来判断是否进行颜色的翻转和过滤
  baseLayer.invertColor = true;
  baseLayer.filterRGB = [0, 50, 100];
  // 更改底色图 着色器的代码【修改底图的片元着色器代码来改变底图的渲染效果】
  // 1. 获取底图的片元着色器源代码：
  const baseFragmentShader =
    viewer.scene.globe._surfaceShaderSet.baseFragmentShaderSource.sources;
  for (let i = 0; i < baseFragmentShader.length; i++) {
    // console.log(baseFragmentShader[i]);
    const strS = 'color = czm_saturation(color, textureSaturation);\n#endif\n';
    let strT = 'color = czm_saturation(color, textureSaturation);\n#endif\n';
    if (baseLayer.invertColor) {
      strT += `
      color.r = 1.0 - color.r;
      color.g = 1.0 - color.g;
      color.b = 1.0 - color.b;
      `;
    }
    if (baseLayer.filterRGB.length > 0) {
      // 着色器是浮点数，计算的时候，需要有小数的部分
      strT += `
      color.r = color.r * ${baseLayer.filterRGB[0]}.0/255.0;
      color.g = color.g * ${baseLayer.filterRGB[1]}.0/255.0;
      color.b = color.b * ${baseLayer.filterRGB[2]}.0/255.0;
      `;
    }
    baseFragmentShader[i] = baseFragmentShader[i].replace(strS, strT);
    // 原文链接：https://blog.csdn.net/qq_33235279/article/details/126524494
  }
};
